<?php

Yii::import('zii.widgets.CPortlet');

class Portlet extends CPortlet
{
	public $autoOpen=true;
	public $url;
	public $id;
	
	public function init()
	{
		//echo CHtml::ajaxLink(Yii::t('Payment','History (click to show)'),$this->createUrl('history',array('id'=>$model->id,'ajax'=>'history-grid')),
		//array('update'=>'#history','beforeSend'=>'js:function(){jQuery(this).addClass("loading");}'),	//FIXME добавление картинки загрузки
		//array('id'=>'showHistory','href'=>$this->createUrl('history',array('id_id'=>$model->id)))
		//);
		//$this->title=(Yii::t('main','Admin Menu'));
		Yii::app()->clientScript->registerScript('toggle_portlet', 
"jQuery('.portlet div.portlet-title').live('click',function() {
    $(this).parent().parent().find('div.portlet-content').toggle();
    return false;
});");
		parent::init();
	}

	protected function renderContent()
	{
		Yii::app()->clientScript->registerScript($this->id, 
"jQuery.ajax({
	'beforeSend':function(){jQuery(this).addClass('loading');},
	'url':'$this->url',
	'cache':false,
	'success':function(html){jQuery('#$this->id').html(html)},
	'error':function(XMLHttpRequest, textStatus, errorThrown){jQuery('#$this->id').html(textStatus)},
	'complete':function(){ $('#$this->id').parent().find('div.loading').hide()},
});");
		echo CHtml::openTag('div',array('class'=>'loading'));
		echo CHtml::image(Yii::app()->theme->baseUrl.'/css/loading.gif');
		echo Chtml::closeTag('div')."\n";
		echo CHtml::openTag('div',array('id'=>$this->id))."\n";
		echo Chtml::closeTag('div')."\n";
	}
}